package net.ch2.pc12.tech.ackborn.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.ch2.pc12.tech.ackborn.dao.CacheDAO;
import net.ch2.pc12.tech.ackborn.dao.SourceDAO;

import android.content.Context;

public class BbsBoardModel {
		
	private List<BbsThreadModel> list;

	private int groupPriority;
	
	private int boardPriority;
	
	private String groupName;
	
	private String boardName;
	
	private String boardId;
	
	private String boardUrl;

	public int getGroupPriority() {
		return groupPriority;
	}

	public void setGroupPriority(int groupPriority) {
		this.groupPriority = groupPriority;
	}

	public int getBoardPriority() {
		return boardPriority;
	}

	public void setBoardPriority(int boardPriority) {
		this.boardPriority = boardPriority;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getBoardName() {
		return boardName;
	}

	public void setBoardName(String boardName) {
		this.boardName = boardName;
	}

	public String getBoardId() {
		return boardId;
	}

	public void setBoardId(String boardId) {
		this.boardId = boardId;
	}

	public String getBoardUrl() {
		return boardUrl;
	}

	public void setBoardUrl(String boardUrl) {
		this.boardUrl = boardUrl;
	}

	public boolean hasCache(Context context){
		CacheDAO cdao = new CacheDAO(context);
		
		return cdao.hasBoardCache(boardId);
	}

	public void load(boolean forceReload,Context context){
		CacheDAO cdao = new CacheDAO(context);
		
		if(forceReload){
			SourceDAO sdao = new SourceDAO(context);
			list = sdao.getBbsThreadModelList(this);
			cdao.storeBbsThreadModelList(list,this);
		}else{
			list = cdao.getBbsThreadModelList(this);
		}

	}

	public List<HashMap<String, String>> getThreadList() {
		// TODO Auto-generated method stub
		ArrayList<HashMap<String,String>> ret = new ArrayList<HashMap<String,String>>();

		for(int i=0;i<list.size();i++){
			HashMap<String,String> map = new HashMap<String,String>();
			BbsThreadModel model = list.get(i);
			map.put("threadNum",Integer.toString(model.getPriority()));
			map.put("threadName",model.getThreadName());
			map.put("threadCount", Integer.toString(model.getCount()));
			map.put("threadRead",Integer.toString(model.getReadCount()));
			map.put("threadId", model.getThreadId());
			map.put("datName", model.getDatName());
			ret.add(map);
		}
		
		return ret;
	}
	
}
